﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using LaunchMeNot.Core;
using Lime49.UI;
using Microsoft.Win32;

namespace LaunchMeNot
{
    /// <summary>
    /// Window for selecting startup entry types.
    /// </summary>
    public partial class WinChooseEntryType : Window
    {
        /// <summary>
        /// Gets or sets the type of entry which was selected.
        /// </summary>
        /// <value>The selected startup entry type.</value>
        public StartupEntryType SelectedType { get; private set; }

        /// <summary>
        /// Initializes a new <see cref="WinChooseEntryType"/> to choose from all types.
        /// </summary>
        public WinChooseEntryType()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Initializes a new <see cref="WinChooseEntryType"/>.
        /// </summary>
        /// <param name="message">The message to display.</param>
        /// <param name="caption">The window caption.</param>
        /// <param name="availableTypes">A bitwise combination of available types.</param>
        public WinChooseEntryType(string message, string caption)
            : this() {
            txtMessage.Text = message;
            this.Title = caption;
        }

        /// <summary>
        /// Validates, then saves the entry.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param>
        private void SaveSelection(object sender, ExecutedRoutedEventArgs e)
        {
            this.SelectedType = (StartupEntryType)Enum.Parse(typeof(StartupEntryType), (e.Parameter ?? string.Empty).ToString());
            DialogResult = true;
        }

        /// <summary>
        /// Closes the window.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param>
        private void CloseWindow(object sender, ExecutedRoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}